<script>
  import $ from 'dfish-widget'
  import Method from '../Method.vue'

  export default {
    mixins: [Method],
    data() {
      return {
        name: '$.vm([target])',
        remark: '获取target所在的view组件实例。<a href="#widgets/View">点击查看view的相关方法</a>。',
        attrs: [{
          name: 'target',
          remark: '来源目标。当target为空时，返回DocView实例',
          type: 'Component / HTMLElement /Event',
        }],
        examples: [{
          remark: '点击"提交"按钮，验证按钮所在view中的表单有效性，并获取表单数据',
          type: 'html',
          code: `
            <template>
              <w-view>
                <w-text name="user" :label="{text: '用户名'}" :required="true"></w-text>
                <w-text name="pswd" :label="{text: '密码'}" :required="true"></w-text>
                <w-button @click="save" text="提交"></w-button>
              </w-view>
            </template>
            <${'script'}>
              import $ from 'dfish-widget'
              export default {
                methods: {
                  save(e) {
                    if ($.vm(e).valid()) {
                      let data = $.vm(e).getPostData()
                      console.log(data)
                    }
                  }
                }
              }
            </${'script'}>
            `
        }]
      }
    }
  }
</script>
